#!/bin/sh
ip netns add ns1
ip link add tap1 type veth peer name tap2
ip link set dev tap2 up
ip link set tap1 netns ns1
ip netns exec ns1 ip link set dev tap1 up 
ip netns exec ns1 ip addr add 10.1.1.1/24 dev tap1

# 创建qbr，连接tap2端
brctl addbr qbr
brctl addif qbr tap2

# 创建br-int，通过veth pair连接qbr网桥
ovs-vsctl add-br br-int
ip link add qvo type veth peer name qvb
ip link set dev qvb up
ip link set dev qvo up
ip link set qbr up
brctl addif qbr qvb
ovs-vsctl add-port br-int qvo

ip link add patch-int type veth peer name patch-tun
ovs-vsctl add-br br-tun
ovs-vsctl add-port br-tun patch-int
ovs-vsctl add-port br-int patch-tun
ovs-vsctl set interface patch-int type=patch
ovs-vsctl set interface patch-tun type=patch
ovs-vsctl set interface patch-int options:peer=patch-tun
ovs-vsctl set interface patch-tun options:peer=patch-int

ip link set br-int up
ip link set br-tun up
ip link set patch-tun up
ip link set patch-int up
# 配置vxlan
ip link add vxlan1 type vxlan id 100 dstport 4789 remote 172.16.0.189 local 172.16.0.188 dev ens33
ip link set vxlan1 up
ovs-vsctl add-port br-tun vxlan1

#host1 增加vm4
ip netns add ns2
ip link add tap10 type veth peer name tap20
ip link set dev tap20 up
ip link set tap10 netns ns2
ip netns exec ns2 ip link set dev tap10 up 
ip netns exec ns2 ip addr add 10.1.1.4/24 dev tap10

brctl addbr qbr20
brctl addif qbr20 tap20


ip link add qvo20 type veth peer name qvb20
ip link set dev qvb20 up
ip link set dev qvo20 up
ip link set qbr20 up
brctl addif qbr20 qvb20
ovs-vsctl add-port br-int qvo20


ovs-vsctl set port qvo tag=10
ovs-vsctl set port qvo20 tag=20
